<?php

function pr($data, $color="white") {
   echo "<div align=\"left\" style=\"background-color: $color\"><xmp>";
   echo print_r($data, 1);
   echo "</xmp></div>";
}

function prdate($date) {
   return ($date != '0000-00-00 00:00:00') ? date('M j', strtotime($date)) : '';
}

function endsWith($fullstr, $endstr) {
   // Get the length of the end string
   $strlen = strlen($endstr);
   // look at the end of fullstr for the substring the size of endstr
   $fullstrend = substr($fullstr, strlen($fullstr) - $strlen);
   // if it matches, it does end with endstr
   return $fullstrend == $endstr;
}

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

   private $_acl = null;

   protected function _initDoctype() {
      $this->bootstrap('view');
      $view = $this->getResource('view');
      $view->doctype('XHTML1_TRANSITIONAL');
   }

   protected function _initAutoload() {
      $autoloader = new Zend_Application_Module_Autoloader(array(
         'namespace' => '',
         //'basePath'  => dirname(__FILE__),
         'basePath' => APPLICATION_PATH.'/modules/default'
      ));

      if(Zend_Auth::getInstance()->hasIdentity()) {
         Zend_Registry::set('role', Zend_Auth::getInstance()->getStorage()->read()->role);
      } else {
         Zend_Registry::set('role', 'guests');
      }
      Zend_Controller_Front::getInstance()->registerPlugin(new App_Plugin_IdentityLoader());
      Zend_Controller_Front::getInstance()->registerPlugin(new App_Plugin_AccessCheck());
      Zend_Session::start();
      
      return $autoloader;
   }

   protected function _initPlugins() {
      $bootstrap = $this->getApplication();
      if ($bootstrap instanceof Zend_Application) {
         $bootstrap = $this;
      }
      $bootstrap->bootstrap('FrontController');
      $front = $bootstrap->getResource('FrontController');

      $plugins = array(
         //new App_Helper_Course()
      );
      foreach($plugins as $plugin) {
         $front->registerPlugin($plugin);
      }
   }

   protected function _initViewHelpers() {
      $this->bootstrap('layout');
      $layout = $this->getResource('layout');

      $view = $layout->getView();
      $view->doctype('XHTML1_TRANSITIONAL');
      $view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset=utf-8');
      $view->headTitle()->setSeparator(' - ');
      
      $view->addHelperPath(APPLICATION_PATH . '/helpers', '');
      Zend_Layout::getMvcInstance()->getView()->addHelperPath('App/Helper', 'App_Helper');
      Zend_Controller_Action_HelperBroker::addPrefix('App_Helper'); 
   }

   protected function _initConfig() {
      Zend_Registry::set('config', $this->getOptions());
      $config = Zend_Registry::get('config');
      $db = Zend_Db::factory($config['resources']['db']['adapter'], $config['resources']['db']['params']);
      Zend_Registry::set('db', $db);
   }

   public function _initRoutes() {

      $router = Zend_Controller_Front::getInstance()->getRouter();
      $routes = array();

      $routes['pagess'] = new Zend_Controller_Router_Route(
         'pages/:page',
            array(
               'module' => 'default',
               'controller' => 'pages',
               'action'     => ':page'
            ),
            array('page' => "\s+")
      );
      
      $routes['langs'] = new Zend_Controller_Router_Route(
         'languages/change/:lang',
            array(
               'module' => 'default',
               'controller' => 'languages',
               'action'     => 'change',
               'lang' => ':lang'
            ),
            array('lang' => "\s+")
      );
      
      $routes[] = new Zend_Controller_Router_Route(
         '/:module/:controller/:action/:page/:sort/:direction',
         array(
            //'module' => 'default',
            //'controller'
            'page' => ':page',
            'sort' => ':sort',
            'direction' => ':direction',
         )
      );
      
      foreach($routes as $name => $route) {
         $router->addRoute($name, $route);
      }
   }



}

































